package team.bailan.service.impl;

import org.springframework.stereotype.Service;
import team.bailan.common.config.ReturnResponse;
import team.bailan.common.enums.ReturnStatus;
import team.bailan.common.process.roblord.RobLord;
import team.bailan.common.process.roblord.RobLordMap;
import team.bailan.entity.dto.RoomInfDTO;
import team.bailan.service.LordService;

@Service
public class LordServiceImpl implements LordService {

    @Override
    public ReturnResponse<String> getInitialRobber(RoomInfDTO roomInfDTO) {
        try {
            int roomId = roomInfDTO.getRoomId();
            RobLord robLord;
            if (RobLordMap.robLordMap.containsKey("room_" + roomId)) {
                robLord = RobLordMap.robLordMap.get("room_" + roomId);
                robLord.getInitialPosition();
            } else {
                robLord = new RobLord();
                robLord.roomId = roomId;
                robLord.getInitialPosition();
                RobLordMap.robLordMap.put("room_" + roomId, robLord);
            }
            return ReturnResponse.OK("获取成功");
        } catch (Exception e) {
            return ReturnResponse.systemException(ReturnStatus.BUSINESS_EXCEPTION);
        }

    }

    @Override
    public ReturnResponse<String> robTheLord(RoomInfDTO roomInfDTO) {
        try {
            int roomId = roomInfDTO.getRoomId();
            RobLord robLord;
            if (RobLordMap.robLordMap.containsKey("room_" + roomId)) {
                robLord = RobLordMap.robLordMap.get("room_" + roomId);
                robLord.robTheLord();
            } else {
                robLord = new RobLord();
                robLord.roomId = roomId;
                robLord.robTheLord();
                RobLordMap.robLordMap.put("room_" + roomId, robLord);
            }
            return ReturnResponse.OK("获取成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ReturnResponse.systemException(ReturnStatus.BUSINESS_EXCEPTION);
        }
    }

    @Override
    public ReturnResponse<String> doNotRobTheLord(RoomInfDTO roomInfDTO) {
        try {
            int roomId = roomInfDTO.getRoomId();
            RobLord robLord;
            if (RobLordMap.robLordMap.containsKey("room_" + roomId)) {
                robLord = RobLordMap.robLordMap.get("room_" + roomId);
                robLord.doNotRobTheLord();
            } else {
                robLord = new RobLord();
                robLord.roomId = roomId;
                robLord.doNotRobTheLord();
                RobLordMap.robLordMap.put("room_" + roomId, robLord);
            }
            return ReturnResponse.OK("获取成功");
        } catch (Exception e) {
            return ReturnResponse.systemException(ReturnStatus.BUSINESS_EXCEPTION);
        }
    }
}
